package Bio::Rambam::Proteomics::Tools::ENGINE_search;
use Moose::Role;
use namespace::autoclean;
use IPC::System::Simple qw(capture);
use Data::Dumper;
use Try::Tiny;

has 'output_file'=>	(is=>'rw',	isa=>'Str',); 


sub template {
    my ($filename, $fillings) = @_;
    my $text;
    local $/;
    open my $fh, "<", $filename or return;
    $text = <$fh>;
    close($fh);                 
    $text =~ s{ %% ( .*? ) %% }
              { exists( $fillings->{$1} ) ? $fillings->{$1} : ""}gex;             
    return $text;
}

sub run_command{
	my ($command,$engine)=@_;
	my $engine_text;
	$engine_text='Comet' 	 if $engine->	isa("Bio::Rambam::Proteomics::Searches::COMET_search");
	$engine_text='OMSSA' 	 if $engine->	isa("Bio::Rambam::Proteomics::Searches::OMSSA_search");
	$engine_text='XTandem' 	 if $engine->	isa("Bio::Rambam::Proteomics::Searches::XTANDEM_search");
	$engine_text='Myrimatch' if $engine->	isa("Bio::Rambam::Proteomics::Searches::MYRIMATCH_search");
	die "Search aborted: Not recognized search engine\n" unless $engine_text;
	try{
		my $t=time();
		print "$engine_text search starting...";
		my $result= capture($command);
		my $t2=time();
		print $t2-$t."s   OK\n";
	}
	catch{
		print "\n$engine_text search failed\n";
		die "$engine_text error: $_"; 
	};
	
}



1;

